<template>
	<view class="page">
		<view class="logo">
			<image src="../../static/logo.png" mode=""></image>
		</view>
		<!-- 填写区 -->
		<view class="input-info">
			<view class="info">
				<input type="text" v-model="form.nickname" maxlength="11" placeholder="请输入昵称">
				<view class="more">
			
				</view>
			</view>
			<view class="info">
				<input type="tel" v-model="form.phone" maxlength="11" placeholder="请输入手机号">
				<view class="more">

				</view>
			</view>
			
			<view class="info">
				<input type="tel" v-model="form.verify" maxlength="6" placeholder="请输入验证码">
				<view class="more">
					<text class="mo" @click="tui.dianji(get_code)" v-if="djs=='获取验证码'">{{djs}}</text>
					<text class="mo" v-if="djs!='获取验证码'">{{djs}}秒后重试</text>
				</view>
			</view>
			<view class="info">
				<input :password='!isPassword' maxlength="26" v-model="form.password" placeholder="请输入密码">
				<view class="more">
					<text class="iconfont" :class="isPassword?'icon-eye-on':'icon-eye-off'"
						@click="isPassword = !isPassword"></text>
				</view>
			</view>
			<view class="info">
				<input :password='!iszfPassword' maxlength="26" v-model="form.pay_password" placeholder="请输入支付密码">
				<view class="more">
					<text class="iconfont" :class="iszfPassword?'icon-eye-on':'icon-eye-off'"
						@click="iszfPassword = !iszfPassword"></text>
				</view>
			</view>
			<view class="info">
				<input type="text" v-model="form.inviter_code"  placeholder="请输入邀请码">
				<view class="more">
			
				</view>
			</view>
			<view class="info">
				<input type="text" v-model="form.inviter_note_code"  placeholder="请输入节点邀请码(非必填)">
				<view class="more">
			
				</view>
			</view>
		</view>
		<!-- 按钮 -->
		<view class="btn-info">
			<view class="btn" :style="isRegister?'opacity:1':'opacity:0.4'" @click="tui.dianji(sumid)">
				<text>注册</text>
			</view>
		</view>
		<!-- 操作 -->
		<view class="operation">
			<text></text>
			<text @click="onLogin">已有账号?登录</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isPassword: false,
				isRegister: false,
				iszfPassword:false,
				// 表单
				form: {
					phone: '',
					verify: '',
					password: '',
					inviter_code:'',
					pay_password:'',
					nickname:'',
					inviter_note_code:''
				},
				djs:'获取验证码',
				is_btn:false,
				timer:null
			};
		},
		onLoad(option) {
			console.log(option)
			this.form.inviter_code =option.recommend
		},
		methods: {
			onLogin() {
				uni.redirectTo({
					url: '/pages/login/login'
				})
			},
			/**
			 * 注册点击
			 */
			
			get_code(){
				let that = this
				if(that.form.phone==''){
					that.tui.toast('请输入手机号');
					return;
				}
				if(that.is_btn){return false}
				let url = ''
				that.tui.request("api.login/send", "POST",{phone:that.form.phone} , false, true, true).then((res) => {
					that.djs = 60
					that.is_btn = true
					that.tui.toast('发送成功');
					that.timer=setInterval(function(){
						that.djs--
						if(that.djs==0){
							clearInterval(that.timer)
							that.djs = '获取验证码'
							that.is_btn = false
						}
					},1000)
				}).catch((res) => {})
			},
			sumid() {
				let that = this
				that.tui.request("api.login/register", "POST", that.form, false, false, false).then((res) => {
					that.tui.toast(res.info)
					if(res.code==1){
						// #ifndef H5
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
						// #endif
						// #ifdef H5
						uni.redirectTo({
							url:'/pages/register/downLoad'
						})
						// #endif
					}
					
				}).catch((res) => {
					
				})
				
			},
		},
		watch: {
			form: {
				handler(newValue, oldValue) {
					if (newValue.phone && newValue.verify && newValue.password && newValue.inviter_code && newValue.pay_password && newValue.nickname) {
						this.isRegister = true;
					} else {
						this.isRegister = false;
					}
				},
				deep: true
			}
		},
		
	}
</script>

<style scoped lang="scss">
	@import 'register.scss';
</style>